home *** CD-ROM | disk | FTP | other *** search
Text File | 2000-10-06 | 4.9 KB | 151 lines | [TEXT/CWIE] |
- /*
-
- SPRITEWORLD CODE STANDARDS
-
- In order to help keep the SpriteWorld code consistent, here are some guidelines that
- contributors should try to follow when writing code for SpriteWorld. This is not a "do or die"
- list of rules; if you do not follow them, we will not throw your code out for that reason
- alone. However, if it's not much more work for you, look over the suggestions below and try
- to follow them when writing code for SpriteWorld. It will help the current maintainer, as
- he won't have to clean up your code later to make it consistent with the rest of SpriteWorld.
-
- Here are the guidelines:
-
- 1) Functions should begin with comments containing the function's name as shown
- in the examples below. There should be a single tab between the "//" and the beginning
- of the function's name. If you change a function's name, remember to update the name
- in the comments as well.
-
- 2) There should be two blank lines between functions, also shown below. In addition,
- there should be one blank line between the comments preceding the function, and the
- function itself.
-
- (more rules after the examples below)
-
- */
-
- ///--------------------------------------------------------------------------------------
- // SWSetSpriteMoveTime
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC void SWSetSpriteMoveTime(
- SpritePtr srcSpriteP,
- long timeInterval)
- {
- SW_ASSERT(srcSpriteP != NULL);
- srcSpriteP->moveTimeInterval = timeInterval;
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWSetSpriteCollideProc
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC void SWSetSpriteCollideProc(
- SpritePtr srcSpriteP,
- CollideProcPtr collideProc)
- {
- SW_ASSERT(srcSpriteP != NULL);
- srcSpriteP->spriteCollideProc = collideProc;
- }
-
-
- /*
-
- 3) Functions should use SW_ASSERT where practical to ensure values passed to the function
- as parameters, and used from structures, are what they are assumed to be. However, these
- should only be used to avoid crashes or other bad behaviour when the programmer makes
- a mistake that should be fixed. These should not be used in situations that are valid
- in a program that works correctly. (i.e. don't use assertion errors as the only way of
- providing the user with an error message telling them they're running in the wrong depth.)
- Note that assertions could be left completely out for final builds.
-
- 4) When adding comments to the code, the comments should use "//" when possible,
- instead of "/*". In addition, the comments should be one tab farther to the right
- than the code that follows:
-
- */
-
- // Set the monster to super-evil mode
- monsterP->mode = kSuperEvil;
-
- /*
-
- 5) The preferred style for braces is the following:
-
- if (stuff)
- {
- whatever;
- }
-
- not:
-
- if (stuff) {
- whatever;
- }
-
- 6) Preferred tab space size is 4 spaces per tab.
- Leave the tab characters in, instead of substituting them with space runs.
-
- 7) Anders recommends using the "ProFont 9 pt" font for the CW editor,
- and an off-white background color (R:100% G:100% B:80% is a nice yellow).
- As well as all syntax-coloring on, incl. Browser Coloring and Custom Keywords.
- Makes stuff much easier to see, and easier on the eyes.
-
- 8) You can use "#pragma mark -" to separate sections of code.
- This gives a divider in CodeWarrior's function popup menu.
-
- 9) All exported globals start with "g", all constants with "k".
- Local declarations should be declared as "static", and NOT appear in any public headers.
-
- 10) All public SpriteWorld functions should start with either "SW..." or "BlitPixie...Proc".
- All exported globals should start with "gSW..." and be declared as "extern" in a header file.
-
- 11) Macros should be in UPPER_CASE_WITH_UNDERSCORES format, and preferrably start with "SW_"
- Simple constants are still given a "k" prefix, as above. Do NOT use the "const" keyword.
-
- 12) Explanation of SpriteWorld's elaborate public headers:
-
- */
-
- // a) this is known as a "shield", and used to avoid including the same header twice,
- // has the same effect as "#pragma once", since that pragma might not be supported?
- #ifndef __SPRITEWORLD__
- #define __SPRITEWORLD__
-
- // b) this declaration keeps the C++ name wrangler from messing up the function names,
- // if we are using SpriteWorld from C++ while still compiling the library as C.
- #ifdef __cplusplus
- extern "C" {
- #endif
-
- // c) this keeps the alignment on 68k (2-byte) boundaries to be compatible with Pascal,
- // it also makes structures the same cross-platform, since they're padded the same way.
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=mac68k
- #endif
-
-
-
-
- // these declarations at the end of the header file just match/reset the ones above.
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=reset
- #endif
-
- #ifdef __cplusplus
- }
- #endif
-
- #endif /* __SPRITEWORLD__ */
-
- /*
-
- 12) Don't forget to do something fun once in a while,
- like play the games you are supposed to be writing :-)
-
-
-
- These guidelines written by Vern Jensen and Anders F Björklund in 1999.
-
- */